using System;
using System.Collections.Generic;
using SCG.SolarVengeanceEngine;
using SCG.SolarVengeanceEngine.BrainInfo;

namespace SCG.SolarVengeance.Brains 
{
  public class TinyBlitz : Brain 
  {
    public override string Author 
    {
      get { 
          return "Beat2k"; 
      }
    }

    public override ChallengeLevel Challenge
    {
        get
        {
            return ChallengeLevel.Difficult;
        }
    }

    public override string Description 
    {
      get { 
          return "This brain is like a TinyBoss, but with Drones!  Only this Brain is not really tiny like him. :)"; 
      }
    }

    public override void Execute() {
        foreach (StarSystemInfo sys in StarSystems) {
            if (sys.OwnedByMe == true) {
                StarShipInfo cship = ClosestStarShip(sys.X,sys.Y,4,FindShipFlags.Enemy,ShipKnownFlags.Either);
                StarShipInfo lship = ClosestStarShip(sys.X, sys.Y, 7, FindShipFlags.Enemy, ShipKnownFlags.Either);
                if (cship != null) {
                    SetAutoShields(sys, true);
                    SetAutoStarShipType(sys, StarShipType.Drone, 2, 0, false);
                }
                else if (lship != null) {
                    SetAutoShields(sys, false);
                    SetAutoStarShipType(sys, StarShipType.Drone, 6, 0, false);
                }
                else {
                    SetAutoShields(sys, false);
                    SetAutoStarShipType(sys, StarShipType.WarShip, 6, Random(3, 5), false);
                }
                if (sys.IsCapital == true)
                    if (sys.Shields < 10)
                        BuildShields(sys, 10);
            }
        }
        foreach (StarShipInfo ship in MyStarShips) {
            StarSystemInfo target = ClosestStarSystem(ship.X, ship.Y, 32767, FindSystemFlags.Unfriendly);
            StarShipInfo eship = ClosestStarShip(ship.X, ship.Y, 32767, FindShipFlags.Enemy, ShipKnownFlags.Either);
            if (ship.ShipType == StarShipType.WarShip) 
            {
                Target(ship, target);
            }
            else if (ship.ShipType == StarShipType.Drone)
            {
                if (eship != null)
                {
                    Move(ship, eship.X, eship.Y);
                }
                else
                {
                    Move(ship, target.X + Random(-7, 7), target.Y + Random(-7, 7));
                }
            }
            else
            {
                Move(ship, target.X + Random(-7, 7), target.Y + Random(-7, 7));
            }
        }
    }
  }
}
